﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.ComponentModel;

namespace Aspfm.Html
{

    // var sortedList = DesignList.OrderBy(a => a.Location_Y).ThenBy(a => a.Location_X);
    // DesignList = sortedList.ToList(); //这个时候会排序

    [Serializable()]
    public class AspfmAll : System.Runtime.Serialization.SerializationBinder
    {
        public List<AspfmEntity> DesignList = null;
        public List<AspfmParams> MyParams = new List<AspfmParams>();
        public List<AspfmDataSource> MyDataSql = new List<AspfmDataSource>();

        public int ALLWidth = 0;
        public int ALLHeight = 0;
        public HCtrol WebFromHtml = null;
        public HCtrol RowHtml = null;
        public string Version = "";

        public override Type BindToType(string assemblyName, string typeName)
        {
            return Type.GetType(String.Format("{0}, {1}", typeName, assemblyName));
        }
    }

    [Serializable()]
    public class AspfmEntity : System.Runtime.Serialization.SerializationBinder
    {
        public Point _Locations = new Point(0,0);
        public Size _Sizes = new Size(0, 0);
        private string _Id = "";
        public AspfmType typekey = AspfmType.Button;
        public string _Text = "";
        public HCtrol HtmlText =null;
        public List<AspfmEntity> ChildList = null;
        public string _QueryCol = "";
        public string _UpdateCol = "";
        public string _DataSource = "";
        public string _dbremark = "";

        public AspfmEntity AspfmCopy(Dictionary<string, AspfmEntity> idlist)
        {
            AspfmEntity Aspfm = new AspfmEntity();
            Aspfm._Locations = this._Locations;
            Aspfm._Sizes = this._Sizes;
            Aspfm._Id = this._Id;
            if (idlist != null && idlist.ContainsKey(this._Id.ToLower()))
            {
                Aspfm._Id = "";
            }
            Aspfm.typekey = this.typekey;
            Aspfm._Text = this._Text;
            Aspfm.HtmlText = this.HtmlText.CopyHCtrol();
            Aspfm._QueryCol = this._QueryCol;
            Aspfm._UpdateCol = this._UpdateCol;
            Aspfm._DataSource = this._DataSource;
            if (this.ChildList != null)
            {
                Aspfm.ChildList = new List<AspfmEntity>();
                foreach (AspfmEntity b in this.ChildList)
                {
                    Aspfm.ChildList.Add(b.AspfmCopy(idlist));
                }
            }
            return Aspfm;
        }

        [Description("控件ID"),
        Category("基本属性"),
        EditorAttribute(typeof(PropertyGridRichText),
        typeof(System.Drawing.Design.UITypeEditor))]
        public string ID { get { return _Id.ToLower(); } set { _Id = value; } }

        [Description("字段描述"),
Category("基本属性"),
EditorAttribute(typeof(PropertyGridRichText),
typeof(System.Drawing.Design.UITypeEditor))]
        public string Dbremark { get { return _dbremark; } set { _dbremark = value; } }

        [Description("控件名称。"),
        Category("基本属性"),
        EditorAttribute(typeof(PropertyGridRichText),
        typeof(System.Drawing.Design.UITypeEditor))]
        public string Text { get { return _Text; } set { _Text = value; } }

        [Description("位置"),
        Category("基本属性")]
        public Point Locations { get { return _Locations; } }

        [Description("大小"),
        Category("基本属性")]
        public Size Sizes { get { return _Sizes; } set { _Sizes = value; } }

        [Description("HTML模版"),
        Category("HTML"),
        EditorAttribute(typeof(PropertyGridRichText),
        typeof(System.Drawing.Design.UITypeEditor))]
        public string Html { get { if (HtmlText == null) { return ""; } return HtmlText.html; } }

        [Description("查询结果集"),
        Category("数据源"),
        EditorAttribute(typeof(PropertyGridRichText),
        typeof(System.Drawing.Design.UITypeEditor))]
        public string DataSource { get { return _DataSource; } }

        [Description("查询字段"),
        Category("数据源"),
        EditorAttribute(typeof(PropertyGridRichText),
        typeof(System.Drawing.Design.UITypeEditor))]
        public string QueryCol { get { return _QueryCol; }  }

        [Description("更新字段。\r\n更新多个字段，使用,号分割"),
        Category("数据源"),
        EditorAttribute(typeof(PropertyGridRichText),
        typeof(System.Drawing.Design.UITypeEditor))]
        public string UpdateCol { get { return _UpdateCol; }  }
        

        public override Type BindToType(string assemblyName, string typeName)
        {
            return Type.GetType(String.Format("{0}, {1}", typeName, assemblyName));
        }
    }
}
